package com.net.oil.push;

import android.content.Context;
import android.content.Intent;

import com.google.gson.Gson;
import com.net.oil.action.ActionDetailActivity;
import com.net.oil.app.Constant;
import com.net.oil.coupon.CouponActivity;
import com.net.oil.order.ReserveDetailActivity;
import com.net.oil.push.bean.PushBean;
import com.net.oil.util.StringUtil;

import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;

public class JPushReceiver extends JPushMessageReceiver {

    @Override
    public void onMessage(Context context, CustomMessage customMessage) {
        super.onMessage(context, customMessage);
    }

    @Override
    public void onNotifyMessageOpened(Context context, NotificationMessage message) {
        //用户点击了通知
        String extra;
        if (message != null){
            extra = message.notificationExtras;
            if (!StringUtil.isEmpty(extra)){
                notificationHandle(context, extra);
            }
        }
    }

    private void notificationHandle(Context context, String json){
        Gson gson = new Gson();
        PushBean pushBean = gson.fromJson(json, PushBean.class);

        switch (pushBean.getNotificationType()){
            case "1":
                break;
            case "2":
                Intent intent3 = new Intent(context, ActionDetailActivity.class);
                intent3.putExtra(Constant.INTENT_ACTION_KEY, Integer.parseInt(pushBean.getNotificationBusiId()));
                context.startActivity(intent3);
                break;
            case "3":
                Intent intent1 = new Intent(context, PushHandleActivity.class);
                intent1.putExtra(Constant.INTENT_PUSH_JSON, json);
                context.startActivity(intent1);
                break;
            case "4":
                Intent intent2 = new Intent(context, PushHandleActivity.class);
                intent2.putExtra(Constant.INTENT_PUSH_JSON, json);
                context.startActivity(intent2);
                break;
            case "5":
                break;
            case "6":
//                context.startActivity(new Intent(context, ReserveActivity.class));
                Intent intent = new Intent(context, ReserveDetailActivity.class);
                intent.putExtra(Constant.INTENT_RESERVE_ID_KEY, Integer.parseInt(pushBean.getNotificationBusiId()));
                context.startActivity(intent);
                break;
            case "7":
                context.startActivity(new Intent(context, CouponActivity.class));
                break;
            default:
                break;
        }
    }
}
